local fayi = fk.CreateSkill {
  name = "fayi",
}

fayi:addEffect(fk.DiscussionFinished, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.results[player.id] and
        table.find(data.tos, function(p)
          return not p.dead and data.results[p.id] and data.results[player.id].opinion ~= data.results[p.id].opinion
        end)
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.filter(data.tos, function(p)
      return not p.dead and data.results[p.id] and data.results[player.id].opinion ~= data.results[p.id].opinion
    end)
    
    local to = player.room:askToChoosePlayers(player,
    { targets = table.map(targets, Util.IdMapper), min_num = 1, max_num = 1, prompt = "#fayi-choose", skill_name = self
    .name, no_indicate = true })
    if #to > 0 then
      event:setCostData(self,{ tos = to })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:damage {
      from = player,
      to = event:getCostData(self).tos[1],
      damage = 1,
      skillName = self.name,
    }
  end,
})

return fayi
